package com.example.plat.service.impl;

import com.example.plat.enity.Activity;
import com.example.plat.mapper.MyActivityMapper;
import com.example.plat.service.MyActivityService;
import com.example.plat.util.TimeFormateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@Service
public class MyActivityServiceImpl implements MyActivityService {

    @Autowired
    MyActivityMapper mapper;

    @Override
    public List<Activity> getMyActivity(String sponsor) throws ParseException {
        List<Activity> activity = mapper.getMyActivity(sponsor);
        List<Activity> list = new ArrayList<>();
        for (Activity a : activity){
            if(!TimeFormateUtil.judgeExpire(a.getTime())){
                list.add(a);
            }
        }
        return list;

    }

    @Override
    public List<Activity> getJoinActivity(Long userId) throws ParseException {
        List<Activity> activity = mapper.getJoinActivity(userId);
        List<Activity> list = new ArrayList<>();
        for (Activity a : activity){
            if(!TimeFormateUtil.judgeExpire(a.getTime())){
                list.add(a);
            }
        }
        return list;
    }

    @Override
    public List<Activity> getCollection(Long userId) {
        return mapper.getCollection(userId);
    }

    @Override
    public List<Activity> getHistoryPublish(String userName) throws ParseException {
        List<Activity> activity = mapper.getMyActivity(userName);
        List<Activity> list = new ArrayList<>();
        for (Activity a : activity){
            if(TimeFormateUtil.judgeExpire(a.getTime())){
                list.add(a);
            }
        }
        return list;
    }

    @Override
    public List<Activity> getHistoryJoin(Long userId) throws ParseException {
        List<Activity> activity = mapper.getJoinActivity(userId);
        List<Activity> list = new ArrayList<>();
        for (Activity a:activity){
            if(TimeFormateUtil.judgeExpire(a.getTime())){
                list.add(a);
            }
        }
        return list;
    }
}
